package 排序;

public class Selection {
    //1. 从0索引开始，跟后面的元素一一比较
    //2. 小的放前面，大的放后面
    public static void main(String[] args) {
        int[] arr = {2,4,1,3,5};
        for (int j = 0; j < arr.length - 1; j++) {
            for (int i = j + 1; i < arr.length; i++) {
                if (arr[j] > arr[i]) {
                    int temp = arr[j];
                    arr[j] = arr[i];
                    arr[i] = temp;
                }
            }
        }
        togo(arr);
    }

    //定义一个方法来遍历数组
    public static void togo(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
